﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WcfService.DBLayer;
using WcfService.ModelLayer;

namespace WcfService.CtrlLayer
{
    public class CtrlVotingResults
    {
        private static IDBVotingResults dbVoting = new DBVotingResults();

        public void makeChoice(int episodeId, int choice)
        {
            //Should be created as Singleton in class VotingResult
            VotingResult vResult = VotingResult.Instance;
            vResult.EpisodeId = episodeId;

            vResult.AddOne(choice);

            SaveResults();
        }

        public void SaveRegId(string regId)
        {
            dbVoting.SaveRegId(regId);
        }

        public int SaveResults()
        {
            VotingResult vResult = VotingResult.Instance;
            int result = dbVoting.SaveResult(vResult);
            vResult.OptionOne = 0;
            vResult.OptionTwo = 0;

            return result;
        }

        public VoteObject voteResult(int episodeId)
        {
            VoteObject vote = new VoteObject();
            vote.Opt1 = dbVoting.GetResultOpt1(episodeId);
            vote.Opt2 = dbVoting.GetResultOpt2(episodeId);
            vote.OptText1 = dbVoting.GetOptionText1(episodeId);
            vote.OptText2 = dbVoting.GetOptionText2(episodeId);

            return vote;
        }
    }
}